#ifndef NEUTRON_DETECTOR_HPP
#define NEUTRON_DETECTOR_HPP

#include "detector_base.hpp"
#include <geometry_msgs/msg/point_stamped.hpp>
#include <vector>
#include <opencv2/opencv.hpp>

namespace detetct_and_navigate {

    struct NeutronDetectionParams
    {
        //高度切片参数
        float search_start_z = 0.35;
        float search_end_z = 0.2;
        float search_step = 0.01;
        float height_range = 0.15;
        ///////?补偿高度呢？////
        float height_offset = 0.05;

        //点云过滤参数
        int min_points_in_slice = 50;

        //矩形拟合参数:最大最小面积
        float rect_min_area = 0.01f;
        float rect_max_area = 0.1f;

        /* //圆形拟合参数：最大最小半径
        float circle_min_radius = 0.02f;
        float circle_max_radius = 0.1f;
        int circle_min_points = 20;

        //中心选择参数
        float center_merge_threshold = 0.03f; */

    };

    class NeutronDetector : public DetectorBase {

    public:

        NeutronDetector() = default;
        ~NeutronDetector() = default;

        bool detectCenter(PointCloud cloud, 
                        geometry_msgs::msg::PointStamped& center_point) override;

        void setParameters(rclcpp::Node* node) override;

    private:

        NeutronDetectionParams params_;

        //检测顶部区域
        PointCloud detectTopRegion(const PointCloud& cloud, float& detected_z);

        //投影到XY平面
        std::vector<cv::Point2f> projectTo2D(const PointCloud& cloud);

        //拟合矩形
        bool fitRectangleAndGetCenter(const std::vector<cv::Point2f>& points,
                        cv::Point2f& center);

        /* //拟合圆形
        bool fitCircle(const std::vector<cv::Point2f>& points,
                    cv::Point2f& center,float& radius);

        //检测内部圆形区域
        std::vector<cv::Point2f> detectInnerCircleRegion(
            const std::vector<cv::Point2f>& all_points,
            const cv::RotatedRect& outer_rect);

        //计算最终中心
        void computeFinalCenter(const cv::Point2f& rect_center,
                                const cv::Point2f& circle_center,
                                cv::Point2f& final_center); */

    };
    
}

#endif